<?php
namespace app\api\controller\biliao;
use think\Controller;
class Index extends Base{	//集成base 使用融云的方法
	public function _empty($name){
        die('非法访问！你的IP已被监控！');
    }
    public function base(){    //获取用户token 创建数据库biliao信息
		$appdata = $this->appdata;	//接收的所有数据 含header
    	$userinfo = $this->userinfo;	//用户信息
        $setting = $this->setting;	//系统参数
        $biliao = $this->biliao;    //币聊表数据
        $RongCloud = $this->RongCloud;	//融云SDK

        if(!$biliao){
            $headimg='http://'.$_SERVER['HTTP_HOST'].'/'.$userinfo['headimg'];
            $name=$userinfo['nicename']?$userinfo['nicename']:$userinfo['uname'];
            //获取token
            $result = $RongCloud->user()->getToken($userinfo['id'], $name, $headimg);
            $result=json_decode($result,true);
            if($result['code']<>200 || !isset($result['token'])){
                apifasong(['zt'=>'0','msg'=>'系统错误']);
            }
            //插入数据库
            $biliao_id=db('biliao')->insertGetId([
                'uid'=>$userinfo['id'],
                'uname'=>$userinfo['uname'],
                'token'=>$result['token'],
                'time'=>time()
            ]);
            if(!$biliao_id){
                apifasong(['zt'=>'0','msg'=>'系统错误']);
            }
            $biliao = db('biliao')->where('uname',$userinfo['uname'])->find();
        }
        $biliao['frs']=frs_info($biliao['frs']);
        $biliao['frsadd']=frsadd_info($biliao['frsadd']);
        $biliao['discussion']=discussion_info($biliao['discussion']);
        $biliao['group']=group_info($biliao['group']);
        $biliao['chatroom']=chatroom_info($biliao['chatroom']);

        apifasong(['zt'=>'1','biliao'=>$biliao]);
    }
}






